<template>
  <div class="shop-header" >
    <nav class="shop-nav" :style="{backgroundImage: `url(${info.bgImg})`}"> <!--字符串相穿的需加`(${})`-->
      <a class="back" @click="$router.back()">
        <i class="iconfont icon-xiaoyuhao"></i>
      </a>
    </nav>
    <div class="shop-content" @click="toggleShopShow">
      <img class="content-image" :src="info.avatar">
      <div class="header-content">
        <h2 class="content-title">
        <span class="content-tag">
          <span class="mini-tag">品牌</span>
        </span>
          <span class="content-name" >{{info.name}}</span>
          <i class="content-icon"></i>
        </h2>
        <div class="shop-message">
          <span class="shop-message-detail">{{info.score}}</span>
          <span class="shop-message-detail">月售{{info.sellCount}}单</span>
          <span class="shop-message-detail">
             {{info.description}}
             <span>约{{info.deliveryTime}}分钟</span>
          </span>
          <span class="shop-message-detail">距离{{info.distance}}</span>
        </div>
      </div>
    </div>
    <div class="shop-header-discounts" @click="toggleSupportShow" v-if="info.supports"><!--用v-if进行判断，有值的时候才显示，避免了异步请求时空数组报错-->
      <div class="discounts-left">
        <div class="activity" :class="supportClacces[info.supports[0].type]">
          <span class="content-tag">
          <span class="mini-tag" style="font-weight: 500;font-size: 16px">
            {{info.supports[0].name}}
          </span>
          </span>
          <span class="activity-content ellipsis">
            {{info.supports[0].content}}
          </span>
        </div>
      </div>
      <div class="discounts-right">
        {{info.supports.length}}个优惠
      </div>
    </div>
    <transition name="fade">
      <div class="shop-brief-modal"  v-show="shopShow">
        <div class="brief-modal-content">
          <h2 class="content-title">
          <span class="content-tag">
          <span class="mini-tag">品牌</span>
          </span>
            <span class="content-name">{{info.name}}</span>
          </h2>
          <ul class="brief-modal-msg">
            <li>
              <h3>{{info.score}}</h3>
              <p>评分</p>
            </li>
            <li>
              <h3>{{info.sellCount}}单</h3>
              <p>月售</p>
            </li>
            <li>
              <h3>{{info.description}}</h3>
              <p>约{{info.deliveryTime}}分钟</p>
            </li>
            <li>
              <h3>{{info.deliveryPrice}}元</h3>
              <p>配送费用</p>
            </li>
            <li>
              <h3>{{info.distance}}</h3>
              <p>距离</p>
            </li>
          </ul>
          <h3 class="brief-modal-title"><span>公告</span></h3>
          <div class="brief-modal-notice">
            {{info.bulletin}}
          </div>
          <div class="mask-footer" @click="toggleShopShow">
            <span class="iconfont icon-guanbi"></span>
          </div>
        </div>
        <div class="brief-modal-cover"></div>
      </div>
    </transition>
    <div>
      <fade-animation>
        <div class="activity-sheet" v-show="supportShow">
          <div class="activity-sheet-content">
            <h2 class="activity-sheet-title">优惠活动</h2>
            <ul class="list" >
              <li class="activity-item"
                  v-for="(item, index) of info.supports"
                  :key="index"
                  :class="supportClacces[item.type]">
              <span class="content-tag">
              <span class="mini-tag">{{item.name}}</span>
              </span>
                <span class="activity-content">{{item.content}}</span>
              </li>
            </ul>
            <div class="activity-sheet-close" @click="toggleSupportShow">
              <span class="iconfont icon-guanbi"></span>
            </div>
          </div>
        </div>
      </fade-animation>
      <div class="activity-sheet-cover" v-show="acty"></div>
    </div>
  </div>
</template>

<script>
import {mapState} from 'vuex'
import FadeAnimation from '../../../components/fade/Fade'
export default {
  name: 'ShopHeader',
  components: {
    FadeAnimation
  },
  computed: {
    ...mapState(['info']) // 对应着shop页面的this.$store.dispatch('getShopInfo')
  },
  data () {
    return {
      supportClacces: ['activity-green', 'activity-red', 'activity-orange'],
      shopShow: false,
      supportShow: false,
      acty: false
    }
  },
  methods: {
    toggleShopShow () {
      this.shopShow = !this.shopShow
    },
    toggleSupportShow () {
      this.supportShow = !this.supportShow
      this.acty = !this.acty
    }
  }
}
</script>

<style lang="stylus" scoped>
  .activity-content
    overflow hidden
    white-space nowrap
    text-overflow ellipsis
  .shop-header
    height 100%
    position relative
    background #fff
    color #fff
    overflow hidden
    .shop-nav
      background-size cover
      background-repeat no-repeat
      height 80px
      padding 10px 20px
      position relative
      &::before
        content ""
        position absolute
        left 0
        right 0
        top 0
        bottom 0
        background-color rgba(119, 103, 137, .43)
      .back
        position: absolute
        top: 20px
        left: 10px
        .icon-xiaoyuhao
          display: block
          padding: 10px
          font-size: 40px
          color: #fff

    .shop-content
      padding 60px 40px 10px 40px
      position relative
      display flex
      background #fff
      text-align center
      img
        box-shadow: 0 0 0.4vw 0 rgba(0, 0, 0, .2);
        position: absolute;
        top: 0;
        left: 50%;
        width: 132px
        height: 132px
        border-radius: 4px
        margin-left -66px
        margin-top -80px
      .header-content
        flex 1
        width 72%
        .content-title
          font-size 40px
          line-height 48px
          font-weight 700
          white-space nowrap
          position relative
          display flex
          align-items center
          justify-content center
          color #333
          .content-tag
            border-radius 4px
            background-image linear-gradient(90deg, #fff100, #ffe339)
            width 72px
            height: 36px
            margin-right 20px
            color #6a3709
            font-style normal
            font-weight 700
            position relative
            .mini-tag
              position absolute
              left 0
              top 0
              right -100%
              bottom -100%
              font-size 48px
              font-weight 600
              transform scale(.5)
              transform-origin 0 0
              display flex
              align-items center
              justify-content center
          .content-name
            font-weight 700
            text-align left
            overflow hidden
            text-overflow ellipsis
          .content-icon
            width 40px
            position relative
            height 32px
            &::after
              content ""
              border-style solid
              border-width: 12px 0 12px 14px
              border-color transparent transparent transparent rgba(0, 0, 0, .67)
              position absolute
              left 16px
              top 6px
      .shop-message
        white-space nowrap
        height 24px
        margin-top 16px
        font-size 22px
        color #333
        .shop-message-detail:not(:last-child)::after
          content " \B7 "
          opacity .2
      .shop-notice
        width 63%
        font-size 22px
        font-weight 300
        color #999
        overflow hidden
        text-overflow ellipsis
        margin 16px auto 20px
        white-space nowrap

    .shop-header-discounts
      display flex
      background #fff
      border-radius 2px
      border 2px solid #eee
      padding 12px 14px
      font-size 22px
      color #666
      margin 0 60px
      align-items center
      .discounts-left
        flex 1
        overflow hidden
        .activity
          display flex
          align-items center
          .content-tag
            border-radius 2px
            width 50px
            height 26px
            margin-right 10px
            color #fff
            font-style normal
            font-weight 700
            position relative
            background-color rgb(112, 188, 70)
            .mini-tag
              position absolute
              left 0
              top 0
              right -100%
              bottom -100%
              font-size 36px
              font-weight 600
              transform scale(.5)
              transform-origin 0 0
              display flex
              align-items center
              justify-content center

      .discounts-right
        width 100px
        flex-shrink 0
        position relative
        padding-right 20px
        text-align right
        &::after
          content ""
          display block
          border-style solid
          border-width 8px 8px 0
          border-color rgba(0, 0, 0, .57) transparent transparent
          position absolute
          top 50%
          transform translateY(-50%)
          right 0

    .shop-brief-modal
      position fixed
      top 0
      left 0
      right 0
      bottom 0
      display flex
      justify-content center
      align-items center
      z-index 52
      flex-direction column
      color #333
      &.fade-enter-active,&.fade-leave-active
        transition opacity .5s
      &.fade-enter,&.fade-leave-to
        opacity 0
      .brief-modal-cover
        position absolute
        width 100%
        height 100%
        top 0
        left 0
        background-color rgba(0, 0, 0, .5)
        z-index 1

      .brief-modal-content
        position relative
        width 80%
        padding 50px 40px
        border-radius 10px
        background #fff
        z-index 99
        display flex
        flex-direction column
        .content-title
          font-size 40px
          line-height 48px
          font-weight 700
          white-space nowrap
          position relative
          display flex
          align-items center
          justify-content center
          > span
            font-weight 600
          .content-tag
            border-radius 4px
            background-image linear-gradient(90deg, #fff100, #ffe339)
            width 72px
            height: 36px
            margin-right 20px
            color #6a3709
            font-style normal
            position relative
            .mini-tag
              position absolute
              left 0
              top 0
              right -100%
              bottom -100%
              font-size 24px
              transform scale(.5)
              transform-origin 0 0
              display flex
              align-items center
              justify-content center
        .brief-modal-msg
          display flex
          margin 40px -20px 0
          > li
            flex 1
            text-align center
            > h3
              font-size 30px
              font-weight 600
              color #333
              margin-bottom 16px
            > p
              font-size 24px
              color #999
        .brief-modal-title
          position relative
          text-align center
          margin 30px auto 30px
          width 170px
          background-image linear-gradient(90deg, #fff, #333 50%, #fff)
          background-size 100% 2px
          background-position 50%
          background-repeat no-repeat
          > span
            font-size 24px
            padding 0 12px
            color #999
            background-color #fff
        .brief-modal-notice
          font-size 26px
          line-height 1.54
          color #333
          overflow-y auto

        .mask-footer
          position absolute
          bottom -120px
          left 50%
          padding 12px
          border 2px solid rgba(255, 255, 255, .7)
          border-radius 50%
          transform translateX(-50%)
          span
            font-size 32px
            color rgba(255, 255, 255, .7)
    .activity-sheet
      position fixed
      top 0
      left 0
      width 100%
      height 100%
      z-index 99
      .activity-sheet-content
        position absolute
        background-color #f5f5f5
        bottom 0
        left 0
        right 0
        z-index 100
        padding 40px 60px
        box-sizing border-box
        transition transform .2s
        will-change transform
        color #333
        .activity-sheet-title
          text-align center
          font-size 40px
          font-weight 600
          margin-bottom 40px
        .list
          font-size 32px
          height 320px
          overflow-y auto
          .activity-item
            margin-bottom 24px
            display flex
            font-size 26px
            align-items center
            &.activity-green
              .content-tag
                background-color rgb(112, 188, 70)
            &.activity-red
              .content-tag
                background-color rgb(240, 115, 115)
            &.activity-orange
              .content-tag
                background-color rgb(241, 136, 79)
            .content-tag
              display inline-block
              border-radius 4px
              width 72px
              height: 36px
              margin-right 20px
              color #fff
              font-style normal
              position relative
              .mini-tag
                position absolute
                left 0
                top 0
                right -100%
                bottom -100%
                font-size 48px
                transform scale(.5)
                transform-origin 0 0
                display flex
                align-items center
                justify-content center
        .activity-sheet-close
          position absolute
          right 12px
          top 20px
          width 50px
          height 50px
          > span
            font-size 40px
.activity-sheet-cover
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 29;
  background-color rgba(0, 0, 0, .5)
</style>
